package models

import (
	"order_srv/basic/config"
	"time"
)

// RulePrice 规则价格表
type RulePrice struct {
	Id                 uint32    `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	CityId             uint64    `gorm:"column:city_id;type:bigint UNSIGNED;default:NULL;" json:"city_id"`
	CarType            string    `gorm:"column:car_type;type:varchar(50);" json:"car_type"`
	EverHourPrice      float64   `gorm:"column:ever_hour_price;type:decimal(10, 2) UNSIGNED;default:NULL;" json:"ever_hour_price"`
	EverKilometerPrice float64   `gorm:"column:ever_kilometer_price;type:decimal(10, 2) UNSIGNED;default:NULL;" json:"ever_kilometer_price"`
	CreatedAt          time.Time `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt          time.Time `gorm:"column:updated_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt          time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// TableName 规则价格表
func (r *RulePrice) TableName() string {
	return "rule_price"
}

// 获取规则价格城市
func (r *RulePrice) GetRulePriceCity() error {
	return config.DB.Where("city_id = ?", r.CityId).Limit(1).Find(&r).Error
}

// 获取规则iD
func (r *RulePrice) GetRulePriceId() error {
	return config.DB.First(&r).Error
}
